﻿using SDDP;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace DotNetStar.TheKing.Domain.Storages
{
    using SDDP;
    public static class ContentStorageExtension
    {
        /// <summary>
        /// 全站访问的查询
        /// </summary>
        /// <param name="contentStorage"></param>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public static IQueryable<Content> QueryNormal(IStorage<Content, long> contentStorage, Expression<Func<Content, bool>> predicate)
            => contentStorage.Query(m => m.Status == Infrastructure.ContentStatus.Normal).Where(predicate);

        /// <summary>
        /// 仅制定用户访问的查询
        /// </summary>
        /// <param name="contentStorage"></param>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public static IQueryable<Content> QueryPrivate(IStorage<Content, long> contentStorage, long userId)
            => contentStorage.Query(m => m.Status == Infrastructure.ContentStatus.Private).Where(m => m.AuthorId == userId);
    }
}
